//
//  ChangePasswordViewController.m
//  InviteJob
//
//  Created by LangLang on 17/10/26.
//  Copyright © 2017年 Shui. All rights reserved.
//

#import "ChangePasswordViewController.h"

@interface ChangePasswordViewController ()
@property (weak, nonatomic) IBOutlet UITextField *txtOldPasswd;

@property (weak, nonatomic) IBOutlet UITextField *txtNewPasswd;

@property (weak, nonatomic) IBOutlet UITextField *txtSurePasswd;


@end

@implementation ChangePasswordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    TitleView(@"修改登录密码")
    _txtOldPasswd.secureTextEntry = YES;
    _txtNewPasswd.secureTextEntry = YES;
    _txtSurePasswd.secureTextEntry = YES;
}


- (IBAction)btnSure:(id)sender {
    
    if (_txtOldPasswd.text.length==0) {
        SHuiMBhudTextTimeStr(@"请输入原密码");
        return;
    }
    if (![SHJudgeTools validatePassword:_txtNewPasswd.text]) {
        SHuiMBhudTextTimeStr(@"请输入6-20位新密码");
        return;
    }
    if (_txtNewPasswd.text != _txtSurePasswd.text) {
        SHuiMBhudTextTimeStr(@"两次输入密码不一致");
        return;
    }
    
    NSString *strUrl = [NSString stringWithFormat:user_modifyPassword_api];
    isUser
    
    NSDictionary *parameter = @{@"phone":user.phone,
                                @"oldpwd":_txtOldPasswd.text,
                                @"newpwd":_txtNewPasswd.text};
    
    [PostNetWorking postNetWorkingStr:strUrl andparameters:parameter Success:^(id responseObject) {
        
        if ([responseObject[@"code"] intValue] == 200) {
            SHuiMBhudTextTimeStr(@"重置密码成功");
            
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                
                [self.navigationController popViewControllerAnimated:YES];
                
            });
            
        }else{
            NSString *mark = [NSString stringWithFormat:@"%@",responseObject[@"mark"]];
            SHuiMBhudTextTimeStr(mark);
        }
        
        
    } failed:^(NSError *error) {
        SHuiMBhudTextTimeStr(@"网络错误");
    }];
    
}

@end
